# Contributor: Jake Buchholz <tomalok@gmail.com>
# Maintainer: Jake Buchholz <tomalok@gmail.com>
pkgname=galera
pkgver=26.4.3
pkgrel=1
_wsrepver=26
pkgdesc="Galera replication - Codership's implementation of the write set replication (wsrep) interface"
url="https://galeracluster.com"
arch="x86 x86_64"  # doesn't work for the others
license="GPL-2.0-or-later"
depends="mariadb"
makedepends="bash boost-dev check-dev cmake python3 scons openssl-dev"
subpackages="$pkgname-arbitrator $pkgname-arbitrator-doc:arbitrator_doc"
source="
	https://github.com/codership/galera/archive/release_$pkgver.tar.gz
	https://github.com/codership/wsrep-API/archive/release_v$_wsrepver.tar.gz
	musl-page-size.patch
	musl-sched_param.patch
	musl-sys-poll-h.patch
	musl-wordsize.patch
"
builddir="$srcdir/$pkgname-release_$pkgver"

prepare() {
	default_prepare

	ln -s /usr/bin/python3 python
	export PATH="$PATH:."
}

build() {
	rmdir wsrep/src
	cp -a ../wsrep-API-release_v$_wsrepver wsrep/src
	RUN_TESTS=0 ./scripts/build.sh
}

check() {
	RUN_TESTS=1 ./scripts/build.sh
}

package() {
	mkdir -p "$pkgdir/usr/lib"
	mv libgalera_smm.so "$pkgdir/usr/lib"
}

arbitrator() {
	url="https://galeracluster.com/library/documentation/arbitrator.html"
	depends=""
	mkdir -p "$subpkgdir/usr/sbin"
	mv "$builddir/garb/garbd" "$subpkgdir/usr/sbin"
}

arbitrator_doc() {
	url="https://galeracluster.com/library/documentation/arbitrator.html"
	depends=""
	mkdir -p "$subpkgdir/usr/share/man/man8"
	mv "$builddir/man/garbd.8" "$subpkgdir/usr/share/man/man8"
	gzip "$subpkgdir/usr/share/man/man8/garbd.8"
}

sha512sums="ede600d6b75d2557b220556d0af4fee64a87b3bc4391dc02209c2d461160fdc1ebe692311c94a69d421515253e219a70d3594a060c9b26561c2bfd5b18b61f17  release_26.4.3.tar.gz
37ddc2c071ec22688ad6bce0cd44285aa00e2c07abce783d5ca6ba655e702feca8397e57c47e961f6ad4d2c14932fc38bac87b8995940b7b38fed655f6cd6671  release_v26.tar.gz
196bae14790d6dad46617d107b5ddac6f01694468fb7a049736c6a21c9857b490863eec66be774eeb01300c0dbf4d9871a1b89da6847d92d67473b3aa80dbd3e  musl-page-size.patch
de08e34bf52cb39353a72a3608053d9204edcddd24f2f7babe2e5eb753d91bd0ca5909ee07a4d6c7ad54e37fba37ad2866403f1805401dcb68b9958514e17ac2  musl-sched_param.patch
6248970137727c56a4c696bfd88eabaa9dc1dd55c287c4f04051f012470714ca53cb88918cd57027793e2705133237a2e7a608dd01ac36a2ae720448922dd4b4  musl-sys-poll-h.patch
2baf88a6c16360ba1ac2ddf7a87a33f84b3039ca9819d84cfdd96b702da1a6050be1b4ac1f3fe6eff7f539158cdb6369906c4821545b1292d98899ec6e13b249  musl-wordsize.patch"
